 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultaCliente.java
 *
 * Created on 25/05/2011, 01:20:48
 */
package consulta;

import Classe.Validacao;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author gladson
 */
public class ConsultaNotaFiscal extends Validacao {

    /** Creates new form ConsultaCliente */
    public ConsultaNotaFiscal() {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        txtConsRazaoClientePJ.setEnabled(false);
        txtConsNomeFantClientePJ.setEnabled(false);
        txtConsCNPJClientePJ.setEnabled(false);
        txtConsInscEstClientePJ.setEnabled(false);
        txtConsContatoClientePJ.setEnabled(false);
        txtConsTelClientePJ.setEnabled(false);
        txtConsEmailClientePJ.setEnabled(false);


    }
    int tipocli;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtConsRazaoClientePJ = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtConsNomeFantClientePJ = new javax.swing.JFormattedTextField();
        txtConsCNPJClientePJ = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        txtConsInscEstClientePJ = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        txtConsContatoClientePJ = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        txtConsTelClientePJ = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtConsEmailClientePJ = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        txtConsDataNota = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtCodigoNota = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cbTipoNota = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        cbNatureza = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        cbTipoCli = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Consulta Nota Fiscal ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel1.setText("Nome/Razão Social");

        txtConsRazaoClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel2.setText("Nome Fantásia");

        txtConsNomeFantClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        txtConsCNPJClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        txtConsCNPJClientePJ.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        jLabel3.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel3.setText("CPF/CNPJ");

        txtConsInscEstClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel4.setText("Insc.Estadual");

        txtConsContatoClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel5.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel5.setText("Contato");

        txtConsTelClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            txtConsTelClientePJ.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel6.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel6.setText("Telefone");

        jLabel7.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel7.setText("E-mail");

        txtConsEmailClientePJ.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jButton1.setText("Consultar");
        jButton1.setToolTipText("Consultar");
        jButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Sair");
        jButton2.setToolTipText("Sair");
        jButton2.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Limpar");
        jButton3.setToolTipText("Limpar");
        jButton3.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        txtConsDataNota.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            txtConsDataNota.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel8.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel8.setText("Data Emissão Nota Fiscal");

        jLabel9.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel9.setText("Código Nota Fiscal");

        txtCodigoNota.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel10.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel10.setText("Tipo de Nota");

        cbTipoNota.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
            "", "ENTRADA", "SAIDA"}));
cbTipoNota.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

jLabel11.setFont(new java.awt.Font("Arial", 1, 11));
jLabel11.setText("Natureza da Operação");

cbNatureza.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
    "", "COMPRA", "VENDA", "MANUTENÇÃO" }));
    cbNatureza.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    jLabel12.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel12.setText("Tipo de Cliente");

    cbTipoCli.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
        "", "Pessoa Fisica", "Pessoa Juridica", "Fornecedor" }));
cbTipoCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
cbTipoCli.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
    cbTipoCliItemStateChanged(evt);
    }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(jButton1)
                    .addGap(18, 18, 18)
                    .addComponent(jButton3)
                    .addGap(18, 18, 18)
                    .addComponent(jButton2))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtConsDataNota)
                        .addComponent(jLabel8))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtCodigoNota, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cbTipoNota, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel11)
                        .addComponent(cbNatureza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cbTipoCli, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtConsCNPJClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtConsInscEstClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(txtConsTelClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel2)
                    .addComponent(txtConsEmailClientePJ)
                    .addComponent(txtConsRazaoClientePJ, javax.swing.GroupLayout.DEFAULT_SIZE, 726, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(txtConsNomeFantClientePJ)
                    .addComponent(txtConsContatoClientePJ)))
            .addContainerGap(32, Short.MAX_VALUE))
    );

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtConsCNPJClientePJ, txtConsInscEstClientePJ, txtConsTelClientePJ});

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cbNatureza, cbTipoCli, cbTipoNota, txtCodigoNota, txtConsDataNota});

    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel8)
                .addComponent(jLabel9)
                .addComponent(jLabel10)
                .addComponent(jLabel12)
                .addComponent(jLabel11))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtConsDataNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtCodigoNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbTipoNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbNatureza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbTipoCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsRazaoClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsNomeFantClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel3)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsCNPJClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel4)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsInscEstClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel5)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsContatoClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel6)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsTelClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jLabel7)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtConsEmailClientePJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1)
                .addComponent(jButton3)
                .addComponent(jButton2))
            .addContainerGap())
    );

    jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cbNatureza, cbTipoCli, cbTipoNota, txtCodigoNota, txtConsDataNota});

    jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-808)/2, (screenSize.height-627)/2, 808, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (validar()) {
            int valFalse = 0;
            String sql = "SELECT NT.DATA_NF,NT.ID_NF,NT.TIPO_NF,NT.NATUREZA_OP_NF,CL.NOME_CLIENTE,CLJ.RAZAO_CLIENTE_PJ,FORN.RAZAO_FORNECEDOR, "
                    + "CL.CPF_CLIENTE,CLJ.CNPJ_CLIENTE_PJ,FORN.CNPJ_FORNECEDOR, "
                    + "CLJ.CONTATO_CLIENTE_PJ,FORN.CONTATO_FORNECEDOR, "
                    + "CL.TEL_CLIENTE,CLJ.TEL_CLIENTE_PJ,FORN.TEL_FORNECEDOR, "
                    + "CL.EMAIL_CLIENTE,CLJ.EMAIL_CLIENTE_PJ,FORN.EMAIL_FORNECEDOR, "
                    + "NT.VALOR_TOT_NF,NT.VALOR_SERV_NF "
                    + "FROM NOTA_FISCAL NT "
                    + "LEFT JOIN CLIENTE  CL ON NT.ID_CLIENTE = CL.ID_CLIENTE "
                    + "LEFT JOIN CLIENTE_PJ CLJ ON NT.ID_CLIENTE_PJ = CLJ.ID_CLIENTE_PJ "
                    + "LEFT JOIN FORNECEDOR FORN ON NT.ID_FORNECEDOR = FORN.ID_FORNECEDOR WHERE 1=1";

            if (!txtConsDataNota.getText().trim().equalsIgnoreCase("/  /")) {
                if (validarData(txtConsDataNota.getText())) {
                    sql = sql + " and NT.DATA_NF='" + txtConsDataNota.getText().trim().toUpperCase() + "'";
                } else {
                    valFalse = 1;
                }

            }

            if ((!txtCodigoNota.getText().trim().equalsIgnoreCase("")) && (txtCodigoNota.getText().trim() != null)) {
                if (validarNumero(txtCodigoNota.getText())) {
                    sql = sql + " and NT.ID_NF ='" + txtCodigoNota.getText().trim().toUpperCase() + "'";
                } else {
                    valFalse = 1;
                }

            }

            if (cbTipoNota.getSelectedItem() != "") {
                sql = sql + " and NT.TIPO_NF='" + cbTipoNota.getSelectedItem().toString() + "'";
            }


            if (cbNatureza.getSelectedItem() != "") {
                sql = sql + " and NT.NATUREZA_OP_NF='" + cbNatureza.getSelectedItem().toString() + "'";
            }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (tipocli == 1) {
                if ((!txtConsRazaoClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsRazaoClientePJ.getText().trim() != null)) {
                    if (validarNome(txtConsRazaoClientePJ.getText())) {
                        sql = sql + " and CL.NOME_CLIENTE LIKE '%" + txtConsRazaoClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if ((!txtConsCNPJClientePJ.getText().trim().equalsIgnoreCase(".   .   -")) && (txtConsCNPJClientePJ.getText().trim() != null) && ((!"".equals(txtConsCNPJClientePJ.getText().trim())))) {

                    sql = sql + " and CL.CPF_CLIENTE ='" + txtConsCNPJClientePJ.getText().trim().toUpperCase() + "'";
                }

                if (!txtConsTelClientePJ.getText().trim().equalsIgnoreCase("(  )    -") && (!"".equals(txtConsTelClientePJ.getText().trim()))) {
                    sql = sql + " and CL.TEL_CLIENTE='" + txtConsTelClientePJ.getText().trim().toUpperCase() + "'";
                }

                if ((!txtConsEmailClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsEmailClientePJ.getText().trim() != null)) {
                    if (validarEmail(txtConsEmailClientePJ.getText())) {
                        sql = sql + " and CL.EMAIL_CLIENTE LIKE '%" + txtConsEmailClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }
            } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            else if (tipocli == 2) {
                if ((!txtConsRazaoClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsRazaoClientePJ.getText().trim() != null)) {
                    if (validarRazaoENome(txtConsRazaoClientePJ.getText())) {
                        sql = sql + " and CLJ.RAZAO_CLIENTE_PJ LIKE '%" + txtConsRazaoClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsNomeFantClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsNomeFantClientePJ.getText().trim() != null)) {
                    if (validarRazaoENome(txtConsNomeFantClientePJ.getText())) {
                        sql = sql + " and CLJ.NOME_FANT_CLIENTE_PJ LIKE '%" + txtConsNomeFantClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }


                if ((!txtConsCNPJClientePJ.getText().trim().equalsIgnoreCase(".   .   /    -")) && (txtConsCNPJClientePJ.getText().trim() != null) && (!"".equals(txtConsCNPJClientePJ.getText().trim()))) {
                    sql = sql + " and CLJ.CNPJ_CLIENTE_PJ ='" + txtConsCNPJClientePJ.getText().trim().toUpperCase() + "'";
                }

                if (!txtConsInscEstClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsInscEstClientePJ.getText().trim() != null)) {
                    if (validarInscEst(txtConsInscEstClientePJ.getText())) {
                        sql = sql + " and CLJ.INSC_EST_CLIENTE_PJ LIKE '%" + txtConsInscEstClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsContatoClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsContatoClientePJ.getText().trim() != null)) {
                    if (validarNome(txtConsContatoClientePJ.getText())) {
                        sql = sql + " and CLJ.CONTATO_CLIENTE_PJ LIKE '%" + txtConsContatoClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsTelClientePJ.getText().trim().equalsIgnoreCase("(  )    -") && (!"".equals(txtConsTelClientePJ.getText().trim()))) {
                    sql = sql + " and CLJ.TEL_CLIENTE_PJ='" + txtConsTelClientePJ.getText().trim().toUpperCase() + "'";
                }

                if ((!txtConsEmailClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsEmailClientePJ.getText().trim() != null)) {
                    if (validarEmail(txtConsEmailClientePJ.getText())) {
                        sql = sql + " and CLJ.EMAIL_CLIENTE_PJ LIKE '%" + txtConsEmailClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }
            } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            else if (tipocli == 3) {
                if ((!txtConsRazaoClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsRazaoClientePJ.getText().trim() != null)) {
                    if (validarRazaoENome(txtConsRazaoClientePJ.getText())) {
                        sql = sql + " and FORN.RAZAO_FORNECEDOR LIKE '%" + txtConsRazaoClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsNomeFantClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsNomeFantClientePJ.getText().trim() != null)) {
                    if (validarRazaoENome(txtConsNomeFantClientePJ.getText())) {
                        sql = sql + " and FORN.NOME_FANT_FORNECEDOR LIKE '%" + txtConsNomeFantClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }


                if ((!txtConsCNPJClientePJ.getText().trim().equalsIgnoreCase(".   .   /    -")) && (txtConsCNPJClientePJ.getText().trim() != null) && (!"".equals(txtConsCNPJClientePJ.getText().trim()))) {

                    sql = sql + " and FORN.CNPJ_FORNECEDOR ='" + txtConsCNPJClientePJ.getText().trim().toUpperCase() + "'";
                }

                if (!txtConsInscEstClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsInscEstClientePJ.getText().trim() != null)) {
                    if (validarInscEst(txtConsInscEstClientePJ.getText())) {
                        sql = sql + " and FORN.INSC_EST_FORNECEDOR LIKE '%" + txtConsInscEstClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsContatoClientePJ.getText().trim().equalsIgnoreCase("") && (txtConsContatoClientePJ.getText().trim() != null)) {
                    if (validarNome(txtConsContatoClientePJ.getText())) {
                        sql = sql + " and FORN.CONTATO_FORNECEDOR LIKE '%" + txtConsContatoClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

                if (!txtConsTelClientePJ.getText().trim().equalsIgnoreCase("(  )    -") && (!"".equals(txtConsTelClientePJ.getText().trim()))) {
                    sql = sql + " and FORN.TEL_FORNECEDOR='" + txtConsTelClientePJ.getText().trim().toUpperCase() + "'";
                }

                if ((!txtConsEmailClientePJ.getText().trim().equalsIgnoreCase("")) && (txtConsEmailClientePJ.getText().trim() != null)) {
                    if (validarEmail(txtConsEmailClientePJ.getText())) {
                        sql = sql + " and FORN.EMAIL_FORNECEDOR LIKE '%" + txtConsEmailClientePJ.getText().trim().toUpperCase() + "%'";
                    } else {
                        valFalse = 1;
                    }

                }

            }

            sql = sql + " ORDER BY NT.TIPO_NF,NT.NATUREZA_OP_NF";

            if (valFalse == 0) {
                ResultadoConsultaNotaFiscal rs = new ResultadoConsultaNotaFiscal();
                rs.iniciar(sql);
                rs.setVisible(true);
                this.dispose();
            }

            valFalse = 0;


        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.dispose();
        ConsultaNotaFiscal cs = new ConsultaNotaFiscal();
        cs.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed
    MaskFormatter mascara = new MaskFormatter();
    private void cbTipoCliItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTipoCliItemStateChanged

        if (cbTipoCli.getSelectedItem().toString().equalsIgnoreCase("Pessoa Fisica")) {
            tipocli = 1;
            try {
                mascara.setMask("###.###.###-##");
                mascara.setPlaceholderCharacter(' ');
                mascara.install(txtConsCNPJClientePJ);
            } catch (ParseException ex) {
                Logger.getLogger(ConsultaNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }
            txtConsRazaoClientePJ.setEnabled(true);
            txtConsNomeFantClientePJ.setEnabled(false);
            txtConsCNPJClientePJ.setEnabled(true);
            txtConsInscEstClientePJ.setEnabled(false);
            txtConsContatoClientePJ.setEnabled(false);
            txtConsTelClientePJ.setEnabled(true);
            txtConsEmailClientePJ.setEnabled(true);
        } else if (cbTipoCli.getSelectedItem().toString().equalsIgnoreCase("Pessoa Juridica")) {
            tipocli = 2;
            try {
                mascara.setMask("##.###.###/####-##");
                mascara.setPlaceholderCharacter(' ');
                mascara.install(txtConsCNPJClientePJ);
            } catch (ParseException ex) {
                Logger.getLogger(ConsultaNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }

            txtConsRazaoClientePJ.setEnabled(true);
            txtConsNomeFantClientePJ.setEnabled(true);
            txtConsCNPJClientePJ.setEnabled(true);
            txtConsInscEstClientePJ.setEnabled(true);
            txtConsContatoClientePJ.setEnabled(true);
            txtConsTelClientePJ.setEnabled(true);
            txtConsEmailClientePJ.setEnabled(true);

        } else if (cbTipoCli.getSelectedItem().toString().equalsIgnoreCase("Fornecedor")) {
            tipocli = 3;

            try {
                mascara.setMask("##.###.###/####-##");
                mascara.setPlaceholderCharacter(' ');
                mascara.install(txtConsCNPJClientePJ);
            } catch (ParseException ex) {
                Logger.getLogger(ConsultaNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }

            txtConsRazaoClientePJ.setEnabled(true);
            txtConsNomeFantClientePJ.setEnabled(true);
            txtConsCNPJClientePJ.setEnabled(true);
            txtConsInscEstClientePJ.setEnabled(true);
            txtConsContatoClientePJ.setEnabled(true);
            txtConsTelClientePJ.setEnabled(true);
            txtConsEmailClientePJ.setEnabled(true);
        } else if (cbTipoCli.getSelectedItem().toString().equalsIgnoreCase("")) {

            mascara.uninstall();
            txtConsCNPJClientePJ.setText("");
            tipocli = 0;
        }


    }//GEN-LAST:event_cbTipoCliItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ConsultaNotaFiscal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbNatureza;
    private javax.swing.JComboBox cbTipoCli;
    private javax.swing.JComboBox cbTipoNota;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtCodigoNota;
    private javax.swing.JFormattedTextField txtConsCNPJClientePJ;
    private javax.swing.JFormattedTextField txtConsContatoClientePJ;
    private javax.swing.JFormattedTextField txtConsDataNota;
    private javax.swing.JTextField txtConsEmailClientePJ;
    private javax.swing.JFormattedTextField txtConsInscEstClientePJ;
    private javax.swing.JFormattedTextField txtConsNomeFantClientePJ;
    private javax.swing.JTextField txtConsRazaoClientePJ;
    private javax.swing.JFormattedTextField txtConsTelClientePJ;
    // End of variables declaration//GEN-END:variables

    public boolean validar() {
        boolean Resultado = true;

        if (cbTipoNota.getSelectedItem().equals("ENTRADA") && cbNatureza.getSelectedItem().equals("VENDA")) {
            JOptionPane.showMessageDialog(rootPane, "Tipo de Operação invalida para o Tipo de Nota!!!");
            Resultado = false;
        } else if (cbTipoNota.getSelectedItem().equals("SAIDA") && cbNatureza.getSelectedItem().equals("COMPRA")) {
            JOptionPane.showMessageDialog(rootPane, "Tipo de Operação invalida para o Tipo de Nota!!!");
            Resultado = false;
        }
        return Resultado;
    }
}
